<template>
<div class="login-bg">
  <mod-container class="login">
    <form class="com-form" @submit.prevent="onSubmit">
      <h1>{{$t('login.pleaseLogin')}}</h1>
      <p>
        <input name="username"
               autocomplete="off"
               :placeholder="$t('login.placeholder.username')"
               v-model="username">
      </p>
      <p>
        <input name="password" type="password"
               autocomplete="off"
               :placeholder="$t('login.placeholder.password')"
               v-model="password"/>
      </p>
      <p>
        <label>
          <input type="checkbox"/>
          {{$t('login.rememberMe')}}
        </label>
      </p>
      <p>
        <button type="submit" class="btn btn-save login-btn">{{$t('login.btn.save')}}</button>
      </p>
      <p>
        <span class="login-forgot" @click.prevent="onClickForgot">{{$t('login.forgot')}}</span>
      </p>
    </form>
    <div class="brand">
      brand
    </div>
  </mod-container>
</div>
</template>
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import ModContainer from '@/modules/ModContainer.vue'
import loginService from '@/services/login-service'
import handleError from '@/errors/error-handler'
import { User } from '@/services/user-service'

@Component({
  name: 'login',
  components: { ModContainer }
})
export default class Login extends Vue {
  username: string = 'zdz'
  password: string = '123'

  mounted () { }

  onSubmit () {
    loginService.login(this.username, this.password)
      .then(user => {
        this.$router.push(this.getRedirectUrl(user))
      })
      .catch(e => handleError(e))
  }

  onClickForgot () {
    throw new Error('unsupported.')
  }

  getRedirectUrl (user: User): string {
    return '/'
  }
}
</script>
<style lang="less">
@import url(../styles/variable.less);

@login-max-width: 960px;

.login-bg {
  background-image: url('../images/login-bg.jpg');
}

.login {
  max-width: @login-max-width !important;
  position: relative;
  height: 100vh;

  .com-form {
    background: #fafafa;
    box-shadow: 0 0 2px #ccc;
    padding: 70px;
    padding-top: 90px;
    font-size: 15px;
    color: #999;
    position: absolute;
    top: 100px;
    bottom: 50px;
    left: 50%;
    right: 15px;

    h1 {
      color: #333;
      font-size: 30px;
      font-weight: 400;
    }

    input:not([type='checkbox']) {
      width: 100%;
      box-shadow: none;
      padding: 10px;
    }

    input:focus {
      box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075),
        0 0 8px rgba(58, 171, 240, 0.6);
    }

    .login-btn {
      display: block;
      width: 100%;
      padding: 8px 16px;
    }

    .login-forgot {
      cursor: pointer;

      &:hover {
        text-decoration: underline;
      }
    }
  }

  .brand {
    padding-right: 41.66666667%;
  }
}
</style>
